package com.hangjiang.gulidear.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hangjiang.gulidear.dao.UserDao;
import com.hangjiang.gulidear.model.User;
import com.hangjiang.gulidear.model.UserRole;

@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	public User findUserByNamePwd(String userName, String password, String role) {
		String hql = "from User u where u.userName = ? and u.loginPwd = ?";
		List<User> us = findByHQL(hql, userName, password);
		for (User u : us) {
			for (UserRole ur : u.getUserRoles()) {
				if (ur.getRole().getRoleId().equals(role)) {
					return u;
				}
			}
		}
		return null;
	}
}
